﻿/// <reference path="_References.js" />
(function () {
    ko.bindingHandlers.jqmRefreshList = {
        update: function (element, valueAccessor) {
            console.log("jqmRefreshList update");

            // Create a dependency
            ko.utils.unwrapObservable(valueAccessor());

            setTimeout(function () {
                var ul = $(element);
                if (ul.closest(".ui-page").length > 0) {
                    ul.listview("refresh");

                    //HACK: these classes seems to dissapear after refresh, add them back again.
                    ul.find("li:first").addClass("ui-corner-top");
                    ul.find("li:last").addClass("ui-corner-bottom");
                }
            }, 1);
        }
    };

    ko.bindingHandlers.jqmRefreshButton = {
        update: function (element, valueAccessor) {
            console.log("jqmRefreshButton update");

            // Create a dependency
            ko.utils.unwrapObservable(valueAccessor());

            setTimeout(function () {
                var el = $(element);
                if (el.closest(".ui-page").length > 0) {
                    el.button();
                }
            }, 1);
        }
    };

    ko.bindingHandlers.jqmRefreshCheckbox = {
        update: function (element, valueAccessor) {
            console.log("jqmRefreshCheckbox update");

            // Create a dependency
            ko.utils.unwrapObservable(valueAccessor());

            setTimeout(function () {
                var el = $(element);
                if (el.closest(".ui-page").length > 0) {
                    el.checkboxradio("refresh");
                }
            }, 1);
        }
    };
})();